package ooap;

/**
 * @author yuisama
 * @date 2022/09/07 20:08
 * 代码块 - 本质就是作用域
 **/
public class CodeBlock {
    int age;
    String name;
    static String country;

    public CodeBlock(int age, String name) {
        System.out.println("1.类中的构造方法");
        this.age = age;
        this.name = name;
    }
    // 直接在类中，使用{}括起来，不加任何修饰符的代码块称之为构造块
    {
        country = "日本";
        System.out.println("2.类中的构造块");
    }
    static {
        country = "中国";
//        age = 10;
        System.out.println("3.类中的静态块");
    }

    public static void main(String[] args) {
        System.out.println("4.主方法开始");
        CodeBlock c1 = new CodeBlock(19,"铭哥");
        CodeBlock c2 = new CodeBlock(19,"铭哥");
        System.out.println("5.主方法结束");
//        CodeBlock c1 = new CodeBlock(20,"鲍老师");
//        System.out.println("c1.age = " + c1.age + ",c1.name = " + c1.name);
//        CodeBlock c2 = new CodeBlock(30,"超哥");
//        System.out.println("c2.age = " + c1.age + ",c2.name = " + c1.name);
    }
}
class StaticBlock {
    public StaticBlock() {
        System.out.println("1.无参构造");
    }
    {
        System.out.println("2.构造块");
    }
    static {
        System.out.println("3.静态代码块");
    }
}